//编辑模板传参
function salt_post_template_edit_value(template_id, template_name, template_txt) {
    document.getElementById("salt_template_id").innerText = template_id;
    document.getElementById("salt_template_name").innerText = template_name;
    document.getElementById("template_txt").value = template_txt;

    $('#salt_template_txt').css({zIndex: '1003', display: 'block', transform: 'scaleX(1)'});
    $('#salt_template_txt').animate({opacity: '1', top: '10%'});
    $('#salt_template_txt').show();
    $('.modal-close').click(function () {
        $('#salt_template_txt').css({zIndex: '1003', display: 'none', transform: 'scaleX(0.7)'});
        $('#salt_template_txt').animate({opacity: '0', top: '415.231px'});
        $('#salt_template_txt').hide();
    });
}

//编辑模板
function salt_post_template_edit() {
    $id = document.getElementById("salt_template_id").innerText;
    $txt = document.getElementById("template_txt").value;
    $.ajax({
        type: 'post',
        url: '/salt/template_edit',
        data: {
            id: $id,
            txt: $txt
        },
        dataType: 'json',
        success: function (data) {
            var obj2 = eval(data);
            swal(obj2.Status)
        }
    });
}

//删除模板
function salt_post_template_del(obj, id) {
    var r = confirm("确定删除该模板？");
    if (r == true) {
        $.ajax({
            type: 'post',
            url: '/salt/template_del',
            data: {
                id: id
            },
            dataType: 'json',
            success: function (data) {
                var obj2 = eval(data);
                if (obj2.Status == "Success") {
                    var index = obj.parentNode.rowIndex;
                    var table = document.getElementById("data-table-simple");
                    table.deleteRow(index)
                } else {
                    swal(obj2.Status)
                }
            }
        });
    }
}

//添加模板
function salt_post_template_add() {
    $id = document.getElementById("add_id").value;
    $txt = document.getElementById("add_template_txt").value;
    $.ajax({
        type: 'post',
        url: '/salt/template_add',
        data: {
            salt_template_name: $id,
            salt_template_txt: $txt
        },
        dataType: 'json',
        success: function (data) {
            var obj2 = eval(data);
            if (obj2.Status == "Success") {
                location.reload()
            } else {
                swal(obj2.Status)
            }
        }
    });
}

//添加一级菜单
function sys_post_one_menu_add() {

    $one_menu_name = document.getElementById("one_menu_name").value;

    if ($one_menu_name == '') {
        swal({
            title: "参数不能为空!",
            text: "检查输入项是否为空",
            timer: 2000,
            showConfirmButton: false
        });
    } else {
        $.ajax({
            type: 'post',
            url: '/sys/menu_add',
            data: {
                menu_grade: 1,       //菜单级别
                menu_name: $one_menu_name,  // 菜单名称
                menu_url: "",  //url地址
                superior_menu_id: 0 //上级菜单ID
            },

            dataType: 'json',
            success: function (data) {
                var obj2 = eval(data);
                if (obj2.Status == "Success") {
                    location.reload()
                } else {
                    swal(obj2.Status)
                }
            }
        });
    }
}

//添加二级菜单
function sys_post_two_menu_add() {
    $two_superior_menu_id = document.getElementById("two_superior_menu_id").value;
    $two_menu_grade = document.getElementById("two_menu_grade").value;
    $two_menu_url = document.getElementById("two_menu_url").value;
    $two_menu_name = document.getElementById("two_menu_name").value;

    if ($two_superior_menu_id == '' || $two_menu_grade == '' || $two_menu_url == '' || $two_menu_name == '') {
        swal({
            title: "参数不能为空!",
            text: "检查输入项是否为空",
            timer: 2000,
            showConfirmButton: false
        });
    } else {
        $.ajax({
            type: 'post',
            url: '/sys/menu_add',
            data: {
                menu_grade: 2,
                menu_name: $two_menu_name,
                menu_url: $two_menu_url,
                superior_menu_id: $two_superior_menu_id
            },

            dataType: 'json',
            success: function (data) {
                var obj2 = eval(data);
                if (obj2.Status == "Success") {
                    location.reload()
                } else {
                    swal(obj2.Status)
                }
            }
        });
    }
}

//添加三级菜单
function sys_post_three_menu_add() {
    $three_superior_menu_id = document.getElementById("three_superior_menu_id").value;
    $three_menu_grade = document.getElementById("three_menu_grade").value;
    $three_menu_url = document.getElementById("three_menu_url").value;
    $three_menu_name = document.getElementById("three_menu_name").value;

    if ($three_superior_menu_id == '' || $three_menu_grade == '' || $three_menu_url == '' || $three_menu_name == '') {
        swal({
            title: "参数不能为空!",
            text: "检查输入项是否为空",
            timer: 2000,
            showConfirmButton: false
        });
    } else {
        $.ajax({
            type: 'post',
            url: '/sys/menu_add',
            data: {
                menu_grade: 3,
                menu_name: $three_menu_name,
                menu_url: $three_menu_url,
                superior_menu_id: $three_superior_menu_id
            },

            dataType: 'json',
            success: function (data) {
                var obj2 = eval(data);
                if (obj2.Status == "Success") {
                    location.reload()
                } else {
                    swal(obj2.Status)
                }
            }
        });
    }
}

//删除菜单
function sys_post_menu_del(obj, id) {
    var r = confirm("确定删除该菜单？");
    if (r == true) {
        $.ajax({
            type: 'post',
            url: '/sys/menu_del',
            data: {
                id: id
            },
            dataType: 'json',
            success: function (data) {
                var obj2 = eval(data);
                if (obj2.Status == "Success") {
                    var index = obj.parentNode.rowIndex;
                    var table = document.getElementById("data-table-simple");
                    table.deleteRow(index)
                } else {
                    swal(obj2.Status)
                }
            }

        });
    }
}

//权限添加
function sys_post_role_pre_add() {
    $role_id = document.getElementById("role_id").value;
    $menu_id = document.getElementById("menu_id").value;

    if ($role_id == '' || $menu_id == '') {
        swal({
            title: "参数不能为空!",
            text: "请选择角色名/菜单",
            timer: 2000,
            showConfirmButton: false
        });
    } else {
        $.ajax({
            type: 'post',
            url: '/sys/perms_add',
            data: {
                role_id: $role_id,
                menu_id: $menu_id

            },
            dataType: 'json',
            success: function (data) {
                var obj2 = eval(data);
                if (obj2.Status == "Success") {
                    location.reload()
                } else {
                    swal(obj2.Status)
                }
            }
        });
    }
}

//权限删除
function sys_post_role_pre_del(pre_id) {

    var r = confirm("确定删除角色权限!");
    if (r == true) {

        $.ajax({
            type: 'post',
            url: '/sys/perms_del',
            data: {
                id: pre_id
            },

            dataType: 'json',
            success: function (data) {
                var obj2 = eval(data);
                if (obj2.Status == "Success") {
                    location.reload()
                } else {
                    swal(obj2.Status)
                }
            }

        });
    }
}
//新增系统角色
function sys_post_role_add() {
    $role_name = document.getElementById("role_name").value;
    if ($role_name == '') {
        swal({
            title: "参数不能为空!",
            text: "请输入角色名称",
            timer: 2000,
            showConfirmButton: false
        });
    } else {
        $.ajax({
            type: 'post',
            url: '/sys/role_add',
            data: {
                role_name: $role_name
            },
            dataType: 'json',
            success: function (data) {
                var obj2 = eval(data);
                if (obj2.Status == "Success") {
                    location.reload()
                } else {
                    swal(obj2.Status)
                }
            }
        });

    }
}
//删除系统角色
function sys_post_role_del(obj, id) {
    var r = confirm("确定删除该角色？");
    if (r == true) {
        $.ajax({
            type: 'post',
            url: '/sys/role_del',
            data: {
                id: id
            },
            dataType: 'json',
            success: function (data) {
                var obj2 = eval(data);
                if (obj2.Status == "Success") {
                    var index = obj.parentNode.rowIndex;
                    var table = document.getElementById("data-table-simple");
                    table.deleteRow(index)
                } else {
                    swal(obj2.Status)
                }
            }
        });
    }
}
//添加系统用户
function sys_post_add_user() {
    $username = document.getElementById("username").value;
    $role_id = document.getElementById("role_id").value;
    $password = document.getElementById("password").value;
    $password_confirm = document.getElementById("password_confirm").value;

    if ($username == '' || $role_id == '' || $password == '' || $password_confirm == '') {
        swal({
            title: "参数不能为空!",
            text: "提示：检查输入项是否为空",
            timer: 2000,
            showConfirmButton: false
        });
        return false;
    } else if ($password.length < 8) {
        swal({
            title: "密码长度不够!",
            text: "不能少于8位",
            timer: 2000,
            showConfirmButton: false
        });
        return false;
    } else if ($password != $password_confirm) {
        swal({
            title: "两次密码输入不一致",
            text: "提示：密码长度不能少于8位",
            timer: 2000,
            showConfirmButton: false
        });
    } else {
        $.ajax({
            type: 'post',
            url: '/sys/user_add',
            data: {
                username: $username,
                role_id: $role_id,
                password: $password
            },
            dataType: 'json',
            success: function (data) {
                var obj2 = eval(data);
                if (obj2.Status == "Success") {
                    location.reload()
                } else {
                    swal(obj2.Status)
                }
            }
        });

    }
}
//删除系统用户
function sys_post_del_user(obj, id) {
    var r = confirm("确定删除该用户？");
    if (r == true) {
        $.ajax({
            type: 'post',
            url: '/sys/user_del',
            data: {
                id: id
            },
            dataType: 'json',
            success: function (data) {
                var obj2 = eval(data);
                if (obj2.Status == "Success") {
                    var index = obj.parentNode.rowIndex;
                    var table = document.getElementById("data-table-simple");
                    table.deleteRow(index)
                } else {
                    swal(obj2.Status)
                }
            }
        });
    }
}
//禁用系统用户
function sys_user_disable(id) {
    var r = confirm("确定禁用该用户？");
    if (r == true) {
        $.ajax({
            type: 'post',
            url: '/sys/user_edit',
            data: {
                id: id,
                status: 1,
                operation: "status"
            },
            dataType: 'json',
            success: function (data) {
                var obj2 = eval(data);
                if (obj2.Status == "Success") {
                    location.reload()
                } else {
                    swal(obj2.Status)
                }
            }
        });
    }
}
//启用系统用户
function sys_user_enable(id) {
    var r = confirm("确定启用该用户？");
    if (r == true) {
        $.ajax({
            type: 'post',
            url: '/sys/user_edit',
            data: {
                id: id,
                status: 0,
                operation: "status"
            },
            dataType: 'json',
            success: function (data) {
                var obj2 = eval(data);
                if (obj2.Status == "Success") {
                    location.reload()
                } else {
                    swal(obj2.Status)
                }
            }
        });
    }
}
//系统用户角色|密码修改传值
function sys_user_role_passwd_edit(id, username) {
    document.getElementById("id").value = id;
    document.getElementById("modif_password_id").value = id;
    document.getElementById("edit_username").value = username;
    document.getElementById("modif_password_username").value = username;

}
//编辑系统用户
function sys_post_edit_user() {
    $id = document.getElementById("id").value;
    $edit_role_id = document.getElementById("edit_role_id").value;

    if ($edit_role_id == '') {
        swal("请选择角色！");
    } else {
        $.ajax({
            type: 'post',
            url: '/sys/user_edit',
            data: {
                id: $id,
                role_id: $edit_role_id,
                operation: "role_id"
            },
            dataType: 'json',
            success: function (data) {
                var obj2 = eval(data);
                if (obj2.Status == "Success") {
                    location.reload()
                } else {
                    swal(obj2.Status)
                }
            }
        });

    }
}

//修改系统用户密码
function sys_user_modif_password() {
    $id = document.getElementById("modif_password_id").value;
    $modif_password_password = document.getElementById("modif_password_password").value;
    $modif_password_confirm = document.getElementById("modif_password_confirm").value;
    if ($modif_password_password == '' || $modif_password_confirm == '') {
        swal({
            title: "密码不能为空",
            text: "提示：密码长度不能少于8位",
            timer: 2000,
            showConfirmButton: false
        });
    } else if ($modif_password_password.length < 8) {
        swal({
            title: "密码长度不够!",
            text: "不能少于8位",
            timer: 2000,
            showConfirmButton: false
        });
        return false;
    } else if ($modif_password_password == $modif_password_confirm) {

        $.ajax({
            type: 'post',
            url: '/sys/user_edit',
            data: {
                id: $id,
                passwd: $modif_password_password,
                operation: "passwd"
            },
            dataType: 'json',
            success: function (data) {
                var obj2 = eval(data);
                if (obj2.Status == "Success") {
                    swal("修改成功!")
                } else {
                    swal("修改失败!")
                }
            }
        });

    } else {
        swal({
            title: "两次密码输入不一致",
            text: "提示：密码长度不能少于8位",
            timer: 2000,
            showConfirmButton: false
        });
    }
}

//数据库添加vpn信息
function sys_post_add_vpn_list() {
    $vpn_name = document.getElementById("vpn_name").value;
    $vpn_labelling = document.getElementById("vpn_labelling").value;
    if ($vpn_name == '' || $vpn_labelling == '') {
        swal({
            title: "参数不能为空!",
            text: "请检查",
            timer: 2000,
            showConfirmButton: false
        });
    } else {
        $.ajax({
            type: 'post',
            url: '/sys/vpn_list_add',
            data: {
                vpn_name: $vpn_name,
                vpn_labelling: $vpn_labelling
            },
            dataType: 'json',
            success: function (data) {
                var obj2 = eval(data);
                if (obj2.Status == "Success") {
                    location.reload()
                } else {
                    swal(obj2.Status)
                }
            }
        });

    }
}

//数据库删除vpn信息
function sys_port_del_vpn_list(obj, id) {
    var r = confirm("确定删该VPN信息？");
    if (r == true) {
        $.ajax({
            type: 'post',
            url: '/sys/vpn_list_del',
            data: {
                id: id
            },
            dataType: 'json',
            success: function (data) {
                var obj2 = eval(data);
                if (obj2.Status == "Success") {
                    var index = obj.parentNode.rowIndex;
                    var table = document.getElementById("data-table-simple");
                    table.deleteRow(index)
                } else {
                    swal(obj2.Status)
                }
            }
        });
    }
}

function port_edit_vpn_list(obj, id) {
    swal("该功能未开发!")

}

//LDAP添加用户组
function ldap_add_group() {
    $description = document.getElementById("description").value;
    $cn = document.getElementById("cn").value;

    if ($description == '' || $cn == '') {
        swal({
            title: "参数不能为空!",
            text: "提示：检查输入项是否为空",
            timer: 2000,
            showConfirmButton: false
        });
    } else {
        $.ajax({
            type: 'post',
            url: '/ldap/group_add',
            data: {
                description: $description,
                cn: $cn
            },


            dataType: 'json',
            success: function (data) {
                var obj2 = eval(data);
                if (obj2.Status == "Success") {
                    location.reload()
                } else {
                    swal(obj2.Status)
                }
            }
        });
    }
}

//LDAP删除用户组
function ldap_group_del(obj, cn) {
    var r = confirm("确定删除该分组？");
    if (r == true) {
        $.ajax({
            type: 'post',
            url: '/ldap/group_del',
            data: {
                cn: cn
            },
            dataType: 'json',
            success: function (data) {
                var obj2 = eval(data);
                if (obj2.Status == "Success") {
                    var index = obj.parentNode.rowIndex;
                    var table = document.getElementById("data-table-simple");
                    table.deleteRow(index)
                } else {
                    swal(obj2.Status)
                }
            }
        });
    }
}

//编辑用户组传值
function ldap_group_edit(cn, description) {
    document.getElementById("edit_cn").value = cn;
    document.getElementById("edit_description").value = description;
}

//LDAP编辑用户组信息
function ldap_group_edit_post() {
    $cn = document.getElementById("edit_cn").value;
    $description = document.getElementById("edit_description").value;


    if ($cn == '' || $description == '') {
        swal({
            title: "参数不能为空!",
            text: "提示：检查输入项是否为空",
            timer: 2000,
            showConfirmButton: false
        });
    } else {
        $.ajax({
            type: 'post',
            url: '/ldap/group_edit',
            data: {
                cn: $cn,
                description: $description
            },

            dataType: 'json',
            success: function (data) {
                var obj2 = eval(data);
                if (obj2.Status == "Success") {
                    location.reload()
                } else {
                    swal(obj2.Status)
                }
            }

        });
    }
}

//LDAP添加用户
function ldap_add_user() {
    var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
    var myreg_mobile = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;

    $givenName = document.getElementById("givenName").value;
    $sn = document.getElementById("sn").value;
    $uid = document.getElementById("uid").value;
    $gidNumber = document.getElementById("gidNumber").value;
    $mobile = document.getElementById("mobile").value;
    $mail = document.getElementById("mail").value;

    if ($givenName == '' || $sn == '' || $uid == '' || $gidNumber == '' || $mobile == '' || $mail == '') {
        swal({
            title: "参数不能为空!",
            text: "提示：检查输入项是否为空",
            timer: 2000,
            showConfirmButton: false
        });
    } else if (!myreg_mobile.test($mobile)) {
        swal({
            title: "电话格式不对",
            text: "电话长度为11位",
            timer: 2000,
            showConfirmButton: false
        });
    } else if ($mobile.length != 11) {
        swal({
            title: "电话格式不对",
            text: "电话长度为11位",
            timer: 2000,
            showConfirmButton: false
        });
    } else if (!myreg.test($mail)) {
        swal({
            title: "请输入有效的邮箱地址!",
            text: "提示：格式不对",
            timer: 2000,
            showConfirmButton: false
        });
    } else {
        $.ajax({
            type: 'post',
            url: '/ldap/user_add',
            data: {
                givenName: $givenName,
                sn: $sn,
                uid: $uid,
                gidNumber: $gidNumber,
                mobile: $mobile,
                mail: $mail

            },


            dataType: 'json',
            success: function (data) {
                var obj2 = eval(data);
                if (obj2.Status == "Success") {
                    location.reload()
                } else {
                    swal(obj2.Status)
                }
            }
        });
    }
}

//LDAP删除用户
function ldap_del_user(obj, uid) {
    var r = confirm("确定删除该用户？");
    if (r == true) {
        $.ajax({
            type: 'post',
            url: '/ldap/user_del',
            data: {
                uid: uid
            },
            dataType: 'json',
            success: function (data) {
                var obj2 = eval(data);
                if (obj2.Status == "Success") {
                    var index = obj.parentNode.rowIndex;
                    var table = document.getElementById("data-table-simple");
                    table.deleteRow(index)
                } else {
                    swal(obj2.Status)
                }
            }
        });
    }
}

//LDAP用户重置密码
function ldap_rese_passwd(uid, mail) {
    var r = confirm("确定重置该用户密码？");
    if (r == true) {
        $.ajax({
            type: 'post',
            url: '/ldap/resepasswd',
            data: {
                uid: uid,
                mail: mail
            },
            dataType: 'json',
            success: function (data) {
                var obj2 = eval(data);
                swal(obj2.Status)
            }
        });
    }
}

//LDAP编辑用户传值
function ldap_user_edit_value(uid, givenName, sn, description, mobile, mail) {

    document.getElementById("edit_givenName").value = givenName;
    document.getElementById("edit_sn").value = sn;
    document.getElementById("edit_uid").value = uid;
    document.getElementById("edit_mobile").value = mobile;
    document.getElementById("edit_mail").value = mail;

    $('#edituser').css({zIndex: '1003', display: 'block', transform: 'scaleX(1)'});
    $('#edituser').animate({opacity: '1', top: '10%'});
    $('#edituser').show();
    $('.modal-close').click(function () {
        $('#edituser').css({zIndex: '1003', display: 'none', transform: 'scaleX(0.7)'});
        $('#edituser').animate({opacity: '0', top: '415.231px'});
        $('#edituser').hide();
    });
}

//LDAP编辑用户信息
function ldap_user_edit_post() {
    var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
    var myreg_mobile = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;

    $givenName = document.getElementById("edit_givenName").value;
    $sn = document.getElementById("edit_sn").value;
    $uid = document.getElementById("edit_uid").value;
    $gidNumber = document.getElementById("edit_gidNumber").value;
    $mobile = document.getElementById("edit_mobile").value;
    $mail = document.getElementById("edit_mail").value;

    if ($givenName == '' || $sn == '' || $uid == '' || $mobile == '' || $mail == '') {
        swal({
            title: "参数不能为空!",
            text: "提示：检查输入项是否为空",
            timer: 2000,
            showConfirmButton: false
        });
    } else if (!myreg_mobile.test($mobile)) {
        swal({
            title: "电话格式不对",
            text: "电话长度为11位",
            timer: 2000,
            showConfirmButton: false
        });
    } else if ($mobile.length != 11) {
        swal({
            title: "电话格式不对",
            text: "电话长度为11位",
            timer: 2000,
            showConfirmButton: false
        });
    } else if (!myreg.test($mail)) {
        swal({
            title: "请输入有效的邮箱地址!",
            text: "提示：格式不对",
            timer: 2000,
            showConfirmButton: false
        });
    } else {
        $.ajax({
            type: 'post',
            url: '/ldap/user_edit',
            data: {
                givenName: $givenName,
                sn: $sn,
                uid: $uid,
                gidNumber: $gidNumber,
                mobile: $mobile,
                mail: $mail

            },
            dataType: 'json',
            success: function (data) {
                var obj2 = eval(data);
                if (obj2.Status == "Success") {
                    location.reload()
                } else {
                    swal(obj2.Status)
                }
            }
        });
    }
}

//LDAP编辑用户sshkey传值
function ldap_user_sshkey_value(uid, sshPublicKey) {
    document.getElementById("edit_uid_sshkey").value = uid;
    document.getElementById("message").value = sshPublicKey;


    $('#sshkey').css({zIndex: '1003', display: 'block', transform: 'scaleX(1)'});
    $('#sshkey').animate({opacity: '1', top: '10%'});
    $('#sshkey').show();
    $('.modal-close').click(function () {
        $('#sshkey').css({zIndex: '1003', display: 'none', transform: 'scaleX(0.7)'});
        $('#sshkey').animate({opacity: '0', top: '415.231px'});
        $('#sshkey').hide();
    });
}

//LDAP编辑用户sshkey
function ldap_user_sshkey_post() {
    $uid = document.getElementById("edit_uid_sshkey").value;
    $sshPublicKey = document.getElementById("message").value;


    $.ajax({
        type: 'post',
        url: '/ldap/sshkey_edit',
        data: {
            uid: $uid,
            sshPublicKey: $sshPublicKey
        },
        dataType: 'json',
        success: function (data) {
            var obj2 = eval(data);
            swal(obj2.Status)
        }
    });
}

//LDAP用户主机管理
function ldap_user_hosts_value(uid) {
    document.getElementById("uid_user_host").value = uid;
    $.ajax({
        type: 'get',
        url: '/ldap/user_host',
        data: {
            uid: uid
        },
        dataType: 'json',
        success: function (data) {
            var obj2 = eval(data);
            if (obj2.Status == "Success") {
                var trStr = '';
                if (obj2.Hostinfo == null || obj2.Hostinfo == "") {
                    trStr += '<tr>';
                    trStr += '<td>' + '当前用户信息为空' + '</td> ';
                    trStr += '<td>' + '' + '</td> ';
                    trStr += '</tr>';

                } else {
                    for (i = 0; i < obj2.Hostinfo.length; i++) {
                        trStr += '<tr>';
                        trStr += '<td>' + obj2.Hostinfo[i].hostname + '</td> ';
                        trStr += '<td onclick=ldap_user_del_host(this,"' + uid + '","' + obj2.Hostinfo[i].hostname + '")> <a href="#" class="btn dropdown-button waves-effect waves-light ">删除</a></td>';
                        trStr += '</tr>';
                    }
                }

                $("#ioioi").html(trStr);
                $('#user_host').css({zIndex: '1003', display: 'block', transform: 'scaleX(1)'});
                $('#user_host').animate({opacity: '1', top: '10%'});
                $('#user_host').show();
                $('.modal-close').click(function () {
                    $('#user_host').css({zIndex: '1003', display: 'none', transform: 'scaleX(0.7)'});
                    $('#user_host').animate({opacity: '0', top: '415.231px'});
                    $('#user_host').hide();
                });

            } else {
                swal(obj2.Status)
            }
        }
    });
}

//LDAP用户VPN管理
function ldap_user_vpns_edit(uid) {

    document.getElementById("uid_user_vpn").value = uid;
    $.ajax({
        type: 'get',
        url: '/ldap/user_vpn',
        data: {
            uid: uid
        },

        dataType: 'json',
        success: function (data) {
            var obj2 = eval(data);
            var trStr = '';
            if (obj2.Status == "Success") {

                if (obj2.Vpninfo == null || obj2.Vpninfo == "") {

                    trStr += '<tr>';
                    trStr += '<td>' + '当前用户信息为空' + '</td> ';
                    trStr += '<td>' + '' + '</td> ';
                    trStr += '</tr>';

                } else {
                    for (i = 0; i < obj2.Vpninfo.length; i++) {
                        trStr += '<tr>';
                        trStr += '<td>' + obj2.Vpninfo[i].vpn + '</td> ';
                        trStr += '<td onclick=ldap_post_del_vpn(this,"' + uid + '","' + obj2.Vpninfo[i].vpn + '")> <a href="#" class="btn dropdown-button waves-effect waves-light ">删除</a></td>';
                        trStr += '</tr>';
                    }
                }
                $("#vpnlist_value").html(trStr);
                $('#user_vpn').css({zIndex: '1003', display: 'block', transform: 'scaleX(1)'});
                $('#user_vpn').animate({opacity: '1', top: '10%'});
                $('#user_vpn').show();
                $('.modal-close').click(function () {
                    $('#user_vpn').css({zIndex: '1003', display: 'none', transform: 'scaleX(0.7)'});
                    $('#user_vpn').animate({opacity: '0', top: '415.231px'});
                    $('#user_vpn').hide();
                });
            } else {
                swal(obj2.Status);
            }

        }
    });
}

//LDAP删除用户主机登录权限
function ldap_user_del_host(obj, uid, hostname) {
    var r = confirm("确定删除主机用户登录权限？");
    if (r == true) {
        $.ajax({
            type: 'post',
            url: '/ldap/user_host',
            data: {
                uid: uid,
                hostname: hostname,
                type: 'del'
            },

            dataType: 'json',
            success: function (data) {
                var obj2 = eval(data);
                if (obj2.Status == "Success") {
                    var index = obj.parentNode.rowIndex;
                    var table = document.getElementById("hostlist");
                    table.deleteRow(index)
                } else {
                    swal(obj2.Status)
                }
            }
        });
    }
}

//LDAP添加用户主机登录权限
function ldap_user_add_host() {
    $hostname = document.getElementById("add_hostname").value;
    $uid = document.getElementById("uid_user_host").value;
    $.ajax({
        type: 'post',
        url: '/ldap/user_host',
        data: {
            uid: $uid,
            hostname: $hostname,
            type: 'add'
        },
        dataType: 'json',
        success: function (data) {
            var obj2 = eval(data);
            swal(obj2.Status)
        }
    });

}

//LDAP添加用户vpn权限
function ldap_post_add_vpn() {
    $vpn_name = document.getElementById("add_vpn").value;
    $uid = document.getElementById("uid_user_vpn").value;
    $.ajax({
        type: 'post',
        url: '/ldap/user_vpn',
        data: {
            uid: $uid,
            vpn_name: $vpn_name,
            type: 'add'
        },
        dataType: 'json',
        success: function (data) {
            var obj2 = eval(data);
            swal(obj2.Status)
        }
    });

}

//LDAP删除用户vpn权限
function ldap_post_del_vpn(obj, uid, vpn_name) {
    var r = confirm("确定删除该用户该VPN？");
    if (r == true) {
        $.ajax({
            type: 'post',
            url: '/ldap/user_vpn',
            data: {
                uid: uid,
                vpn_name: vpn_name,
                type: 'del'
            },

            dataType: 'json',
            success: function (data) {
                var obj2 = eval(data);
                if (obj2.Status == "Success") {
                    var index = obj.parentNode.rowIndex;
                    var table = document.getElementById("vpnlist");
                    table.deleteRow(index)
                } else {
                    swal(obj2.Status)
                }
            }
        });
    }
}

//更新/添加saltstack主机信息
function salt_update_hosts() {
    var r = confirm("更新时间较长，请稍后查看");
    if (r == true) {
        swal({
            title: "主机列表更新中，请稍后",
            text: "预计30-80秒",
            showConfirmButton: false
        });
        $.ajax({
            type: 'post',
            url: '/salt/update_hosts',
            dataType: 'json',
            success: function (data) {
                var obj2 = eval(data);
                if (obj2.Status == "Success") {
                    location.reload()
                } else {
                    swal(obj2.Status)
                }
            }
        });
    }
}

//添加代码发布项目
function delpoy_post_project_add() {
    var obj = document.getElementsByName('server_name');
    var server_host = '';
    for (var i = 0; i < obj.length; i++) {
        if (obj[i].checked) {
            server_host += obj[i].value + ' '
        }
    }
    $add_project_name = document.getElementById("add_project_name").value;
    $add_project_type = document.getElementById("add_project_type").value;
    if ($add_project_name == '') {
        swal({
            title: "项目名称不能为空!",
            text: "提示：检查输入项是否为空",
            timer: 2000,
            showConfirmButton: false
        });
    } else if ($add_project_type == '') {
        swal({
            title: "请选择项目类型!",
            text: "提示：检查输入项是否为空",
            timer: 2000,
            showConfirmButton: false
        });
    } else {
        $.ajax({
            type: 'post',
            url: '/deploy/project',
            data: {
                project_name: $add_project_name,
                project_type: $add_project_type,
                operation_type: 'add',
                server_host: server_host
            },
            dataType: 'json',
            success: function (data) {
                var obj2 = eval(data);
                if (obj2.Status == "Success") {
                    location.reload()
                } else {
                    swal(obj2.Status)
                }
            }
        });
    }
}

//删除代码发布项目
function delpoy_post_project_del(obj, id) {
    var r = confirm("确定删除该项目？");
    if (r == true) {
        $.ajax({
            type: 'post',
            url: '/deploy/project',
            data: {
                id: id,
                operation_type: 'del'
            },
            dataType: 'json',
            success: function (data) {
                var obj2 = eval(data);
                if (obj2.Status == "Success") {
                    var index = obj.parentNode.rowIndex;
                    var table = document.getElementById("data-table-simple");
                    table.deleteRow(index)
                } else {
                    swal(obj2.Status)
                }
            }
        });
    }
}

//项目发布页面
function deploy_project(project) {
    window.open("/deploy/java?project="+project);
}

function deploy_post_project(project_id,project_edition,publisher) {
    var restart = prompt("是否重启程序: [y/n]");
    if (restart != null) {
        swal({
            title: "代码发布中，请稍后",
            text: "预计30-80秒",
            showConfirmButton: false
        });
        $.ajax({
            type: 'post',
            url: '/deploy/java',
            data: {
                project_id: project_id,
                project_edition: project_edition,
                publisher:publisher,
                restart:restart
            },
            dataType: 'json',
            success: function (data) {
                var obj2 = eval(data);
                if (obj2.Status == "Success") {
                    location.reload()
                } else {
                    swal(obj2.Status)
                }
            }
        });
    }
}

function show_svn_ci_file(info){
    var trStr = '';
    trStr += '<tr>';
    trStr += '<td>' + info + '</td> ';
    trStr += '<td>' + '' + '</td> ';
    trStr += '</tr>';
    $("#vpnlist_value").html(trStr);
    $('#file_list').css({zIndex: '1003', display: 'block', transform: 'scaleX(1)'});
    $('#file_list').animate({opacity: '1', top: '10%'});
    $('#file_list').show();
    $('.modal-close').click(function () {
        $('#file_list').css({zIndex: '1003', display: 'none', transform: 'scaleX(0.7)'});
        $('#file_list').animate({opacity: '0', top: '415.231px'});
        $('#file_list').hide();
    });

}